<?php
require_once('modules/Dashboard/Activity.php');
require_once('modules/Dashboard/Model_Research.php');
global $mod_strings, $current_user;

$smarty = new Sugar_Smarty();
if(isset($_POST['from']) && isset($_POST['to'])){
    $from = $_POST['from'];
    $to = $_POST['to'];
}else{
    $from = date('Y-m').'-01';
    $to = date('Y-m-t');
}

$res = new Research($from, $to);
$act = new Activity();
$access = $act->hasUserAccessToActivity($current_user->id);
$researchAccess = $res->hasUserAccessToResearch($current_user->id);

if(is_admin($current_user) || $access || $researchAccess){

    $smarty->assign('report', $res->createResearchReport($from, $to));
    $smarty->assign('from', $from);
    $smarty->assign('to', $to);
    $smarty->assign('displayReportsType', false);
    $smarty->assign('modStrings', $mod_strings);
    $smarty->assign('accessToUserReport', $access);
    echo $smarty->fetch('modules/Dashboard/research.tpl');

}

